"""URL Paths and Routers for Blog App"""
from rest_framework.routers import SimpleRouter

from .viewsets import PostViewSet


class PostRouter(SimpleRouter):
    """
    Override the SimpleRouter for Blog Posts

    DRF's routers expect there to only be a single variable for finding objects. However,
    our blog posts needs three! WE therefore override the Router's behavior to make it do
    what we want.
    """

    def get_lookup_regex(self, *args, **kwargs):
        """
        Return Regular Expression Pattern for URL Path
            <int:year>/<int:month>/<str:slug>
        """
        return (
            r"(?P<year>\d+)/"
            r"(?P<month>\d+)"
            r"(?P<slug>[\w\-]+)"
        )


post_router = PostRouter()
post_router.register(
    'blog', PostViewSet, basename="api-post"
)

urlpatterns = post_router.urls


# from django.urls import path
#
# from .views import PostAPIDetail, PostAPIList
#
# urlpatterns = [
#     path(
#         "blog/", PostAPIList.as_view(), name="api-post-list"
#     ),
#     path(
#         "blog/<int:year>/<int:month>/<str:slug>/",
#         PostAPIDetail.as_view(),
#         name="api-post-detail",
#     ),
# ]
#
